/* Android-Michi is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * Android-Michi is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Android-Michi; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */
package view;

import com.chaski.michi.*;

import controller.Controller;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TouchManager {
	Activity activity;
	Controller controller;

	public TouchManager(Activity _activity, Controller _controller) {
		activity = _activity;
		controller = _controller;
	}

	public void gridDisplayed() {
		Button button;


		try {
			button = (Button)activity.findViewById(R.id.btnButton00);
			button.setOnClickListener(btn00Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton10);
			button.setOnClickListener(btn10Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton20);
			button.setOnClickListener(btn20Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton01);
			button.setOnClickListener(btn01Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton11);
			button.setOnClickListener(btn11Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton21);
			button.setOnClickListener(btn21Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton02);
			button.setOnClickListener(btn02Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton12);
			button.setOnClickListener(btn12Listener);
		}
		catch(Exception e) {

		}	

		try {
			button = (Button)activity.findViewById(R.id.btnButton22);
			button.setOnClickListener(btn22Listener);
		}
		catch(Exception e) {

		}	
		

	}


	/********listeners *********************/

	private OnClickListener btn00Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn00Event();
		}
	};

	private OnClickListener btn10Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn10Event();
		}
	};

	private OnClickListener btn20Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn20Event();
		}
	};


	private OnClickListener btn01Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn01Event();
		}
	};

	private OnClickListener btn11Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn11Event();
		}
	};

	private OnClickListener btn21Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn21Event();
		}
	};


	private OnClickListener btn02Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn02Event();
		}
	};

	private OnClickListener btn12Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn12Event();
		}
	};

	private OnClickListener btn22Listener = new OnClickListener() {
		public void onClick(View v) { 
			controller.btn22Event();
		}
	};
	

}
